package android.slc.design;


import android.content.Context;
import android.graphics.Color;

import androidx.annotation.ColorInt;
import androidx.annotation.IntRange;
import androidx.core.content.ContextCompat;

/**
 * @author slc
 * @date 2020-08-19 13:06
 */
public class DesignColorUtils {
    private static final float colorLevel6 = 256F / 16;
    private static int[] uiColorArray;

    public static int[] getUiColorArray(Context context) {
        if (uiColorArray == null) {
            uiColorArray = new int[]{
                    ContextCompat.getColor(context, R.color.ui_color_blue1),
                    ContextCompat.getColor(context, R.color.ui_color_orange2),
                    ContextCompat.getColor(context, R.color.ui_color_red1),
                    ContextCompat.getColor(context, R.color.ui_color_green1),
                    ContextCompat.getColor(context, R.color.ui_color_blue2),
                    ContextCompat.getColor(context, R.color.ui_color_green2),
                    ContextCompat.getColor(context, R.color.ui_color_orange1),
                    ContextCompat.getColor(context, R.color.ui_color_purple1)
            };
        }
        return uiColorArray;
    }

    @ColorInt
    public static int getWhiteLevel16(@IntRange(from = 0, to = 16) int level) {
        return getColorLevel16(Color.WHITE, level);
    }

    @ColorInt
    public static int getBlackLevel16(@IntRange(from = 0, to = 16) int level) {
        return getColorLevel16(Color.BLACK, level);
    }

    @ColorInt
    public static int getColorLevel16(int colorRgb, @IntRange(from = 0, to = 16) int level) {
        int red = Color.red(colorRgb);
        int green = Color.green(colorRgb);
        int blue = Color.blue(colorRgb);
        return argb((int) (colorLevel6 * level * 256), red, green, blue);
    }

    @ColorInt
    public static int argb(
            @IntRange(from = 0, to = 255) int alpha,
            @IntRange(from = 0, to = 255) int red,
            @IntRange(from = 0, to = 255) int green,
            @IntRange(from = 0, to = 255) int blue) {
        return (alpha << 24) | (red << 16) | (green << 8) | blue;
    }
}
